﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class adm_vlg_postdetails : System.Web.UI.Page
{
    VLGDataContext _db4 = new VLGDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["currentItem"] = "";
        if (!IsPostBack)
        {
            this.loadiDuLieuCT();
            
        }
    }
    void loadiDuLieuCT()
    {
        string idG= Request.QueryString["id"];
        //string idC=Request.QueryString["c"];

        try
        {
            int intG2 = int.Parse(idG);

            Gig gig22 = _db4.Gigs.Single(idgg=>idgg.idGig==intG2);
            lbltags.Text = gig22.Tags;
            lblGioithieu.Text = gig22.TuGioiThieu;
            lblNgay.Text = gig22.SoNgayCanDeXong.ToString();
            lblNguoiPost.Text = gig22.VLGAccount.UsernameE;
            avar_revi.Src = ResolveClientUrl("~/avatar/"+gig22.VLGAccount.urlAvatar);
            avar_revi.Width = 50;
            avar_revi.Height = 45;
            // Load hinh
            img_a.Src = ResolveClientUrl("~/upload/"+gig22.UrlHinh1);
            // Load Comment
            var itemCM = from cm in _db4.GigComments
                         where cm.AnHien == true && cm.idGig == intG2
                         select new { cm.idGig,cm.NoiDungBL,cm.NgayBL,cm.VLGAccount.UsernameE,cm.VLGAccount.idAcc};
                         //select cm;
          
            SqlCommand cmd = (SqlCommand)_db4.GetCommand(itemCM);
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);

            CollectionPager1.MaxPages = 1000;
            CollectionPager1.PageSize = 5;
            CollectionPager1.DataSource = dt.DefaultView;
            CollectionPager1.BindToControl = DataList1;
            DataList1.DataSource = CollectionPager1.DataSourcePaged;
            DataList1.DataBind();
            // bai viet lien quan
            var itemBVLQ = from bv in _db4.Gigs
                           where bv.idAcc == gig22.idAcc
                           select new { bv.idGig,bv.TenCongViec,bv.Category.idCategory};
            rptLienQuan.DataSource = itemBVLQ.Skip(gig22.idGig);
            rptLienQuan.DataBind();
                          
        }
        catch
        {

        }
    }

}
